/**
 **********************************************************************
 * File name: filter.h
 *
 * COPYRIGHT (C) 2018-2020, ZLOS Development Team
 *
 * The license and distribution terms for this file may be found in 
 * the LICENSE file.
 *
 * Author: ChenLong (Add new editor)
 * Email: worldlong@foxmail.com
 **********************************************************************
**/
#pragma once
/*
*/
class LPF2
{
public:
  void init(float fs, float fc);
  float apply(float data); 
  
private:
  
  bool _inited;
  
  double _y0;
  double _y1;
  double _y2;
  
  double _b0;
  double _b1;
  double _b2;
  double _a1;
  double _a2;
};
/*
*/
class Filter
{
public:
  Filter(int order, double *a, double *b, double *x, double *y);
  double apply(double x);
  float apply(float x);
  
private:
  int _order;
  double *_a;
  double *_b;
  double *_x;
  double *_y;
};
/*
*/
class LPF3 : public Filter
{
public:
  LPF3(double*a, double*b) :
  Filter(3, a, b, _xx, _yy)
  {
    for(int i=0; i<4; i++) {
      _xx[i] = 0;
      _yy[i] = 0;
    }
  }
  
private:
  double _xx[4];
  double _yy[4];
};
/*
*/
class LPF4 : public Filter
{
public:
  LPF4(double*a, double*b) :
  Filter(4, a, b, _xx, _yy)
  {
    for(int i=0; i<5; i++) {
      _xx[i] = 0;
      _yy[i] = 0;
    }
  }
  
private:
  double _xx[5];
  double _yy[5];
};




